/*-------------------<-- Start of Description-->---------------------\ | SAS job scheduler; | |---------------------<-- End of Description-->----------------------| |--------------------------------------------------------------------| |------------<-- Start of Files or Arguments Needed-->---------------| | Arguments: | | path: file path; | | date: date when you want to submit the file; | | NOTE: you can give multiple dates, times, datetimes; | | or you can give the time part to the next argument; | | time: time you want to submit the file; | |-------------<-- End of Files or Arguments Needed-->----------------| |--------------------------------------------------------------------| |------------------<-- Start of Files Created-->---------------------| | Example: | | %scheduler(C:\Duo\RSdata\SASTmpFiles\open.sas, 08aug03, 11:35:00); | | Usage: %scheduler(path, date, time); | \-------------------<-- End of Files Created-->---------------------*/ %macro scheduler/parmbuff; /*--------------------------------------------\ | Copy Right: Duo Zhou; | | Created: 11-6-2002 11:01pm; | \--------------------------------------------*/ %global __lastschpath; %local path date time _xschedulerx_ _xschedulepos_ _xschedulelen_ _xscheduleoldstr_ _xschedulenewstr_ _schedulenewstr_ _xschedulevarcnt_ _xschedulevar_ _xschedulex2_ _xschedulex3_ filename filepath start _dcount_ _datei_ dummy; %if (%quote(&syspbuff) ne) %then %let syspbuff=%sysfunc(translate(%quote(%substr(%quote(%trim(%quote(%left(%quote(&syspbuff))))), 2, %eval(%length(%trim(%quote(%left(%quote(&syspbuff)))))-2))), %str(%'), %str(%"))); %let path=; %let time=; %let date=; %let filename=; %let filepath=; %let _xschedulerx_=%sysfunc(rxparse($(1))); %let _xschedulepos_=0; %let _xschedulelen_=0; %let _xscheduleoldstr_=; %let _xschedulenewstr_=; %do %while( %sysfunc(rxmatch(&_xschedulerx_, %quote(&syspbuff))) ); %syscall rxsubstr(_xschedulerx_, syspbuff, _xschedulepos_, _xschedulelen_); %let _xscheduleoldstr_=%quote(%substr(%quote(&syspbuff), &_xschedulepos_, &_xschedulelen_)); %let _xschedulenewstr_=%quote(%sysfunc(translate(%quote(&_xscheduleoldstr_), À, %quote(%(), Á, %quote(%)), ´, %quote(,), ®, %quote( )))); %let syspbuff=%sysfunc(tranwrd(%quote(&syspbuff), %quote(&_xscheduleoldstr_), %quote(&_xschedulenewstr_))); %let _xschedulepos_=0; %let _xschedulelen_=0; %let _xscheduleoldstr_=; %let _xschedulenewstr_=; %end; %let _schedulenewstr_=&syspbuff; %let _xschedulevarcnt_=0; %do %while(%length(%qscan(%nrbquote(&_schedulenewstr_), %eval(&_xschedulevarcnt_+1), %nrbquote(,)))); %let _xschedulevarcnt_=%eval(&_xschedulevarcnt_+1); %let _xschedulevar_=%nrbquote(%qscan(%nrbquote(&_schedulenewstr_), &_xschedulevarcnt_, %nrbquote(,))); %let _xschedulevar_=%sysfunc(translate(%quote(&_xschedulevar_), '(', 'À', ')', 'Á', ',', '´', ' ', '®')); %let _xschedulex2_=%trim(%left(%qscan(%quote(&_xschedulevar_), 1, %str(=)))); %let _xschedulex3_=%substr(%quote(&_xschedulevar_), %eval(%index(%quote(&_xschedulevar_),%str(=))+1), %eval(%length(&_xschedulevar_)-%index(%quote(&_xschedulevar_),%str(=)))); %if (not %index(%BQUOTE(%trim(%BQUOTE(%left(%BQUOTE(&_xschedulevar_))))), %str(=))) %then %do; %if (%index(%BQUOTE(%trim(%BQUOTE(%left(%BQUOTE(&_xschedulex2_))))), %str(%()) eq 1) and (%index(%BQUOTE(%trim(%BQUOTE(%left(%BQUOTE(%sysfunc(reverse(&_xschedulex2_))))))), %str(%))) eq 1) %then %let _xschedulex3_=%substr(%quote(%trim(%quote(%left(%quote(&_xschedulex2_))))), 2, %eval(%length(%trim(%quote(%left(%quote(&_xschedulex2_)))))-2)); %if (%quote(&_xschedulevarcnt_) = %quote(1)) %then %let path=&_xschedulex3_; %else %if (%sysfunc(rxmatch(%sysfunc(rxparse($a)), &_xschedulex3_))) or (%index(%quote(&&_xschedulex3_), %quote( ))) or or (%index(%quote(&&_xschedulex3_), %quote(,))) %then %let date=&_xschedulex3_; %else %if (not %sysfunc(rxmatch(%sysfunc(rxparse($a)), &_xschedulex3_))) and (not %index(%quote(&&_xschedulex3_), %quote( ))) and (not %index(%quote(&&_xschedulex3_), %quote(,))) %then %let time=&_xschedulex3_; %end; %else %if (%index(%BQUOTE(%trim(%BQUOTE(%left(%BQUOTE(&_xschedulex3_))))), %str(%()) eq 1) and (%index(%BQUOTE(%trim(%BQUOTE(%left(%BQUOTE(%sysfunc(reverse(&_xschedulex3_))))))), %str(%))) eq 1) and (%index(%nrbquote(upcase(%nrbquote(%sysfunc(compress(%nrbquote(&_xschedulex2_)))))), WHERE=) le 1) %then %let &_xschedulex2_=%substr(%quote(%trim(%quote(%left(%quote(&_xschedulex3_))))), 2, %eval(%length(%trim(%quote(%left(%quote(&_xschedulex3_)))))-2)); %else %let &_xschedulex2_=&_xschedulex3_; %end; %if (%quote(&path) ne) %then %do; %let path=%sysfunc(compress(%quote(%sysfunc(compress(%quote(%trim(%quote(%left(%quote(&path))))), '"'))), "'")); %let path=%sysfunc(translate(%quote(&path), %str(\), %str(/))); %let filename=%sysfunc(reverse(%qscan(%quote(%sysfunc(reverse(%quote(&path)))), 1, %str(\)))); %if (%index(%quote(%upcase(&filename)), %quote(.SAS))) %then %let filepath=%substr(&path, 1, %eval(%length(&path)-%length(&filename))); %else %do; %put ==> Alert! A SAS file is required!; %goto finish; %end; %end; %if (%quote(&filepath) ne) %then %let __lastschpath=%trim(%left(%sysfunc(dequote(&filepath)))); %else %if (%quote(&filepath) eq) and (%MacroVarChk(__lastschpath)) %then %if (%quote(&__lastschpath) ne) %then %let filepath=&__lastschpath; %else %do; ==> Alert! A valid file path is needed!; %goto finish; %end; %let start=%sysfunc(datetime()); %if (%quote(&date) eq) %then %let date=%sysfunc(date()); %let _dcount_=0; %do %while(%length(%nrbquote(%scan(%nrbquote(&date), %eval(&_dcount_+1), %nrbquote((), ))))); %let _dcount_=%eval(&_dcount_+1); %let _datei_=%nrbquote(%qscan(%nrbquote(&date), &_dcount_, %nrbquote((), ))); %if (%sysfunc(rxmatch(%sysfunc(rxparse($a)), &_datei_))) and (%quote(&time) ne) %then %let _datei_=%trim(%left(&_datei_)):%trim(%left(&time)); %if (%sysfunc(rxmatch(%sysfunc(rxparse($a)), &_datei_))) and (%quote(&time) eq) %then %let _datei_=%trim(%left(&_datei_)); %else %if (not %sysfunc(rxmatch(%sysfunc(rxparse($a)), &_datei_))) and (%quote(&time) eq) %then %let _datei_=%trim(%left(%sysfunc(date(), date9.))):%trim(%left(&_datei_)); %else %if (not %sysfunc(rxmatch(%sysfunc(rxparse($a)), &_datei_))) and (%quote(&time) ne) %then %let _datei_=%trim(%left(%sysfunc(date(), date9.))):%trim(%left(&time)); %put NOTE: Wait! Checking schedules...; options nonotes; data scheduler; format start end datetime20.; start=&start; end="&_datei_"dt; do while(start=end) then call system("'%trim(%left(%sysfunc(pathname(sasroot))))\SAS.EXE' '%trim(%left(&filepath))%trim(%left(&filename))' -nologo -config '%trim(%left(%sysfunc(pathname(sasroot))))\SASV8.CFG'"); run; options notes; %put NOTE: File "%trim(%left(&filepath))%trim(%left(&filename))" is submitted at %trim(%quote(%left(%quote(%sysfunc(datetime(), datetime30.))))); %end ; %delds(scheduler); %finish: %mend scheduler ;